/* eslint-disable react/prop-types */
/* eslint-disable react/react-in-jsx-scope */
import { Redirect, Route } from 'react-router'
import { hasToken } from '@/utils/storage'
import { useHistory } from 'react-router'

export default function AuthRoute (props) {
  console.log(props, 'props')
  const Com = props.component
  const history = useHistory()
  return (
    <Route
      path={props.path}
      render={() => {
        if (hasToken()) {
          return <Com />
        } else {
          return (
            <Redirect
              to={{
                pathname: '/login',
                state: { from: history.location.pathname }
              }}
            />
          )
        }
      }}
    />
  )
}
